package com.gitee.wsl.android.ui.ext

import android.app.Activity.RESULT_OK
import android.app.NotificationManager
import android.content.Intent
import android.os.Build
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts
import com.gitee.wsl.android.ui.activity.activityRegistryForResultLauncher
import com.gitee.wsl.android.ext.NotificationScope
import com.gitee.wsl.android.notification.notificationManager
import timber.log.Timber

object NotificationExt {

}

//开启横幅通知返回
fun NotificationScope.bannerNotificationAble(activity: ComponentActivity, packageName:String, channelId:String): Boolean = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    val bannerImportance = notificationManager.getNotificationChannel(channelId).importance
    if (bannerImportance == NotificationManager.IMPORTANCE_DEFAULT) {
        val bannerLauncher =
            activity.activityRegistryForResultLauncher(ActivityResultContracts.StartActivityForResult()) {
                if (it.resultCode == RESULT_OK) {
                    Timber.d("返回结果")
                }
            }

        val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
            .putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
            .putExtra(Settings.EXTRA_CHANNEL_ID, channelId)
        bannerLauncher.launch(intent); false

    } else true
} else true
